package server.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import server.business.mapper.BloodSampleStateMapper;
import server.business.mapper.SampleMapper;
import server.business.pojo.*;
import server.business.service.BloodSampleReviewService;
import server.business.service.SampleService;
import server.business.vo.Result;
import server.business.vo.ResultExpand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;


import com.alibaba.excel.EasyExcel;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;

/**
 * @author ccb
 * @date 2022/07/25
 */
@Controller
public class SampleController {
    @Autowired
    private SampleMapper sampleMapper;
    @Autowired
    private SampleService sampleService;
    @Autowired
    private BloodSampleStateMapper bloodSampleStateMapper;
    @Autowired
    private BloodSampleReviewService bloodSampleReviewService;
    
//    @RequestMapping("/index")
//    public String toIndex(){
//        return "index-tabs";
//    }
//
//    @RequestMapping("/blood_sample")
//    public String toSample(){
//        return "pages/sample_information";
//    }

    /**
     * 查询数据
     */
    @RequestMapping("/blood_sample/query")
    @ResponseBody
    public List<SampleData> queryData(){
        List<SampleData> list = sampleService.queryData();
        return list;
    }

    /**
     * 删除通过id
     */
    @PutMapping("/blood_sample/deleteById")
    @ResponseBody
    public Result deleteById(Integer id){
        Result result = new Result();
        result = sampleService.deleteById(id);
        return result;
    }

    /**
     * 获取页面
     *血液标本分页查询
     */
    @RequestMapping("/blood_sample/listByPage")
    @ResponseBody
    public ResultExpand getPage(HttpServletRequest request, HttpServletResponse response){
        ResultExpand resultExpand = new ResultExpand();
        resultExpand = sampleService.getPage(request, response);
        return resultExpand;
    }

    /**
     * 搜索血液样本
     *
     * @param request  请求
     * @param response 响应
     * @return {@link ResultExpand}
     */
    @RequestMapping("/blood_sample/searchSample")
    @ResponseBody
    public ResultExpand searchSample(HttpServletRequest request, HttpServletResponse response){
        ResultExpand resultExpand = new ResultExpand();
        resultExpand = sampleService.searchSample(request, response);
        return resultExpand;
    }

    /**
     * 增加血液样本
     *
     * @param sampleData 样本数据
     * @return {@link Result}
     */
    @RequestMapping(value = "/blood_sample/addSample")
    @ResponseBody
    public Result addBloodSample(@RequestBody SampleData sampleData) {
        Result result = new Result();
        result = sampleService.addBloodSample(sampleData);
        return result;
    }

    /**
     * 签收样本
     *
     * @param sampleData 样本数据
     * @return {@link String}
     */
    @RequestMapping(value = "/blood_sample/receiveSample")
    @ResponseBody
    public Result receiveSample(@RequestBody SampleData sampleData) {
        Result result = new Result();
        result = sampleService.receiveSample(sampleData);
        return result;
    }

    /**
     * 血液样品出库
     *
     * @param sampleData 样本数据
     * @return {@link Result}
     */
    @RequestMapping("/blood_sample/outSample")
    @ResponseBody
    public Result outSample(@RequestBody SampleData sampleData){
        Result result = new Result();
        result = sampleService.outSample(sampleData);
        return result;
    }

    /**
     * 丢弃血液样品
     *
     * @param sampleData 样本数据
     * @return {@link Result}
     */
    @RequestMapping("/blood_sample/discardSample")
    @ResponseBody
    public Result discardSample(@RequestBody SampleData sampleData){
        Result result = new Result();
        result = sampleService.discardSample(sampleData);
        return result;
    }

    /**
     * 下载excel
     *
     * @param request  请求
     * @param response 响应
     */
    @RequestMapping("/blood_sample/downloadExcel")
    public void downloadExcel(HttpServletRequest request, HttpServletResponse response){
       sampleService.downloadExcel(request, response);
    }
}
